home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume6 / malloc.patch < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  2.1 KB

  1. Subject:  v06i100:  Bug fix for "smarter malloc" (malloc.patch)
  2. Newsgroups: mod.sources
  3. Approved: rs@mirror.UUCP
  4.  
  5. Submitted by: cca!astrovax!wls (William L. Sebok)
  6. Mod.sources: Volume 6, Issue 100
  7. Archive-name: malloc.patch
  8.  
  9. My recent malloc posting [Volume 6, #54 --r$] has a bug in the realloc
  10. routine.  If the area of memory is to be expanded in size and if it
  11. sits adjacent to the "break" then the area is expanded by moving the
  12. break.  Unfortunately, in this case I forgot to mark the area of memory
  13. as Busy and take it off the Free queues.  Horrible things may then
  14. happen if a latter malloc grabs this memory hunk.  Thanks to elsie!ado
  15. for finding the bug.
  16.  
  17. Bill Sebok            Princeton University, Astrophysics
  18. {allegra,akgua,cbosgd,decvax,ihnp4,noao,philabs,princeton,vax135}!astrovax!wls
  19.  
  20.  
  21. #!/bin/sh
  22. # This is a shell archive.  Remove anything before this line,
  23. # then unpack it by saving it in a file and typing "sh file".
  24. # Wrapped by mirror!rs on Mon Aug 11 16:07:13 EDT 1986
  25. # Contents:  malloc.patch
  26.  
  27. echo x - malloc.patch
  28. if test -f malloc.patch ; then
  29.     echo malloc.patch exists, putting output in $$malloc.patch
  30.     OUT=$$malloc.patch
  31. else
  32.     OUT=malloc.patch
  33. fi
  34. sed 's/^XX//' > $OUT <<'@//E*O*F malloc.patch//'
  35. XX*** /tmp/,RCSt1000667    Sat Aug  2 22:49:47 1986
  36. XX--- realloc.c    Thu Jul 31 17:01:57 1986
  37. XX***************
  38. XX*** 71,76
  39. XX          nbytes += sizeof(struct overhead);
  40. XX          BRK((char *)p + nbytes);
  41. XX          p->ov_length = nbytes;
  42. XX          return(mem);
  43. XX      }
  44. XX  
  45.  
  46. XX--- 71,79 -----
  47. XX          nbytes += sizeof(struct overhead);
  48. XX          BRK((char *)p + nbytes);
  49. XX          p->ov_length = nbytes;
  50. XX+         /* declare it to be busy */
  51. XX+         remque(TOBUK(p));
  52. XX+         p->ov_magic = MAGIC_BUSY;
  53. XX          return(mem);
  54. XX      }
  55. @//E*O*F malloc.patch//
  56. chmod u=rw,g=rw,o=rw malloc.patch
  57.  
  58. echo Inspecting for damage in transit...
  59. temp=/tmp/sharin$$; dtemp=/tmp/sharout$$
  60. trap "rm -f $temp $dtemp; exit" 0 1 2 3 15
  61. cat > $temp <<\!!!
  62.       20      60     450 malloc.patch
  63. !!!
  64. wc  malloc.patch | sed 's=[^ ]*/==' | diff -b $temp - >$dtemp
  65. if test -s $dtemp
  66. then echo "Ouch [diff of wc output]:" ; cat $dtemp
  67. else echo "No problems found."
  68. fi
  69. exit 0
  70.